<?php

function ftp_get_file($ftpserver,$ftpuser,$ftppass,$path,$remote_file,$local_file,&$msg,$timeout=3)
{
	DAO_Log::debug( __FUNCTION__.":[$ftpuser@$ftpserver] $path/$remote_file to $local_file");
	$conn_id = ftp_connect($ftpserver,null,3);
	if($conn_id===false)
	{
		$msg= __FUNCTION__.':error: ftp connect ';
		return -1;
	}
	if($timeout>0)
	{
		ftp_set_option($conn_id,FTP_TIMEOUT_SEC,$timeout);
	}
	$ret = ftp_login($conn_id, $ftpuser, $ftppass);
	if(!$ret)
	{
		$msg= __FUNCTION__.":error: ftp login for $ftpuser ";
		ftp_close(($conn_id));
		return -2; 
	}
	$remote_file = $path."/".$remote_file;
	$ret = ftp_get($conn_id,$local_file,$remote_file,FTP_BINARY);
	if(!$ret)
	{
			$msg= __FUNCTION__.":error: ftp get $remote_file to $local_file";
			ftp_close(($conn_id));
			return -3;
	}
	ftp_close(($conn_id));
	return 0;
}

?>